package com.qfedu.edu.entrypoint;

import com.qfedu.edu.result.R;
import com.qfedu.edu.result.ResponseCode;
import com.qfedu.edu.utils.HttpResponseUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author xiaobobo
 * @title: MyAuthenticationEntryPoint
 * @projectName cd-fy-2401-third-project-parent
 * @description: 没有权限访问的时候 执行的方法
 * @date 2024/9/14  9:28
 */
@Component
public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
     R error = R.error(ResponseCode.NO_PERMISSION_EXCEPTION);
     //然后响应给前端
     HttpResponseUtils.sendResponse(response,error);
    }
}
